package com.akino.gulimall.cart.vo;


import java.math.BigDecimal;
import java.util.List;

/**
 * @author Akino
 * @version 1.0
 * 购物车
 */
public class Cart {
    List<CartItem> items;  // 购物车中的商品
    private Integer countNum = 0; // 购物车中的商品数量
    private Integer countType = 0; // 购物车中商品种类的数量
    private BigDecimal totalAmount = new BigDecimal("0.00"); // 商品总价
    private BigDecimal reduce;  // 减免的价格

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int i = 0;
        if (this.items != null && this.items.size()>0){
            for (CartItem cartItem :items) {
                i+=cartItem.getCount();
            }
        }
        return i;
    }

    public Integer getCountType() {
        int i = 0;
        if (this.items != null && this.items.size()>0){
            for (CartItem cartItem :items) {
                i+=1;
            }
        }
        return i;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        // 计算购物项总价
        for (CartItem cartItem :items) {
            if (cartItem.getCheck()) {
                amount = amount.add(cartItem.getTotalPrice());
            }
        }
        // 减去优惠总价
        amount = amount.subtract(getReduce());
        return amount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
